package org.joa.manager;

import org.joa.actor.Actor;
import org.joa.actor.ActorName;
import org.joa.actor.transaction.Transaction;

public class ManagedActor {
    private ActorName actorName;
    private Class<? extends Actor> actorClass;
    private Actor currentInstance;
    private long currentRevision = ActorManager.instance.getCurrentRevision();
    private Transaction currentTransaction;

    public ManagedActor(Class<? extends Actor> actorClass) throws InstantiationException,
        IllegalAccessException {
        this(actorClass.newInstance());
    }

    public ManagedActor(Actor actor) {
        this.actorName = actor.self();
        this.actorClass = actor.getClass();

        this.currentInstance = actor;
    }

    public ActorName getActorName() {
        return actorName;
    }

    public Class<? extends Actor> getActorClass() {
        return actorClass;
    }

    public Actor getCurrentInstance() {
        return currentInstance;
    }

    public long getCurrentRevision() {
        return currentRevision;
    }

    public void setCurrentRevision(long currentRevision) {
        this.currentRevision = currentRevision;
    }

    public Transaction getCurrentTransaction() {
        return currentTransaction;
    }

    public void setCurrentInstance(Actor currentInstance) {
        this.currentInstance = currentInstance;
    }

    public void setCurrentTransaction(Transaction transaction) {
        this.currentTransaction = transaction;
    }

    public String toString() {
        return actorClass.getName() + " [" + actorName.toString() + " r" + currentRevision + "] " +
            currentInstance.toString();
    }
}
